package org.apache.portals.tutorials;



import java.io.IOException;
import java.io.PrintWriter;
import java.net.*;
import java.io.*;

import javax.portlet.PortletConfig;
import javax.portlet.GenericPortlet;
import javax.portlet.PortletException;
import javax.portlet.PortletRequestDispatcher;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import javax.portlet.WindowState;

public class PostProject extends GenericPortlet {

    private static final String NORMAL_VIEW = "/normal.jsp";
    private static final String MAXIMIZED_VIEW = "/maximized.jsp";
    private static final String HELP_VIEW = "/help.jsp";

    private PortletRequestDispatcher normalView;
    private PortletRequestDispatcher maximizedView;
    private PortletRequestDispatcher helpView;

    public void doView( RenderRequest request, RenderResponse response )
        throws PortletException, IOException {

        if( WindowState.MINIMIZED.equals( request.getWindowState() ) ) {
        	//dispatch.forward(arg0, arg1)
        	//1java.net.HttpURLConnection http = new HttpURLConnection(new URL("http://localhost:8080/test/ProjectController"));
        	response.setContentType("text/html; charset=utf-8");
            PrintWriter outPrintWriter = response.getWriter();
            outPrintWriter.println("hello this is newportlet");
            outPrintWriter.println("<form method='post' action='http://localhost:8090/test/ProjectController?projectaction=post'>"+
            
                       "Project Name <input type='text' name='projectName'><br/>"+
                       
        	"Project Description <TEXTAREA NAME='projectDiscription' ROWS=8 COLS=50></TEXTAREA>"+
        	"Category <select name='category' >"+
        	 " <option value='research'>Research project</option>"+
        	  "<option value='mobile>Mobile Project</option>"+
        	 " <option value='web'>Web Project</option>"+
        	 "<option value='desktop'>Desktop Application Project</option>"+
        	"</select>"+ 
        	"<input type='submit' value='Post Project' />"+
        	"</form>");
        	
        	return;
        }

        if ( WindowState.NORMAL.equals( request.getWindowState() ) ) {
            //normalView.include( request, response );
        	response.setContentType("text/html; charset=utf-8");
            PrintWriter outPrintWriter = response.getWriter();
            outPrintWriter.println("hello this is newportlet");
            outPrintWriter.println("<form method='post' action='http://localhost:8090/test/ProjectController?projectaction=post'>"+
            
                       "Project Name <input type='text' name='projectName'><br/>"+
                       
        	"Project Description <TEXTAREA NAME='projectDiscription' ROWS=8 COLS=50></TEXTAREA>"+
        	"Category <select name='category' >"+
        	 " <option value='research'>Research project</option>"+
        	  "<option value='mobile>Mobile Project</option>"+
        	 " <option value='web'>Web Project</option>"+
        	 "<option value='desktop'>Desktop Application Project</option>"+
        	"</select>"+ 
        	"<input type='submit' value='Post Project' />"+
        	"</form>");
        	
        	
        } else {
            maximizedView.include( request, response );
        }
    }

    protected void doHelp( RenderRequest request, RenderResponse response )
        throws PortletException, IOException {

        helpView.include( request, response );

    }

    public void init( PortletConfig config ) throws PortletException {
        super.init( config );
        normalView = config.getPortletContext().getRequestDispatcher( NORMAL_VIEW );
        maximizedView = config.getPortletContext().getRequestDispatcher( MAXIMIZED_VIEW );
        helpView = config.getPortletContext().getRequestDispatcher( HELP_VIEW );
    }

    public void destroy() {
        normalView = null;
        maximizedView = null;
        helpView = null;
        super.destroy();
    }

}


